import type { EnvData, MessageItem, BuildingStatus } from '../types'

export class EnvDataGenerator {
  static generateEnvData(): EnvData {
    return {
      temperature: 20 + Math.random() * 15,
      humidity: 40 + Math.random() * 40,
      airQuality: 60 + Math.random() * 40,
      uvIndex: 1 + Math.random() * 8,
      lightIntensity: 800 + Math.random() * 800,
      pressure: 1000 + Math.random() * 50,
      windSpeed: 5 + Math.random() * 20,
      pm25: 10 + Math.random() * 80
    }
  }
}

export class MessageGenerator {
  private static messageTemplates = [
    '设备运行正常',
    '系统检测到异常',
    '数据更新完成',
    '网络连接稳定',
    '温度超出正常范围'
  ]

  private static types: MessageItem['type'][] = ['info', 'warning', 'success', 'error']

  static generateMessage(): MessageItem {
    return {
      id: Math.random().toString(36).substr(2, 9),
      content: this.messageTemplates[Math.floor(Math.random() * this.messageTemplates.length)],
      type: this.types[Math.floor(Math.random() * this.types.length)],
      time: new Date().toLocaleTimeString()
    }
  }

  static generateMessageList(count: number = 5): MessageItem[] {
    return Array.from({ length: count }, () => this.generateMessage())
  }
}

export class BuildingGenerator {
  private static buildingNames = [
    '教学楼A', '教学楼B', '图书馆', '实验楼', '办公楼', '食堂'
  ]

  private static statuses: BuildingStatus['status'][] = ['online', 'maintenance', 'offline']

  static generateBuildingStatus(): BuildingStatus[] {
    return this.buildingNames.map((name, index) => ({
      id: (index + 1).toString(),
      name,
      status: this.statuses[Math.floor(Math.random() * this.statuses.length)],
      deviceCount: Math.floor(Math.random() * 20) + 5,
      energyConsumption: Math.floor(Math.random() * 100) + 20,
      lastUpdate: new Date().toLocaleTimeString(),
      position: { x: Math.random() * 100, y: Math.random() * 100 }
    }))
  }
}

export class EnergyDataGenerator {
  static generateEnergyData() {
    const categories = ['电力', '水', '燃气']
    const buildings = ['教学楼', '宿舍楼', '办公楼']
    const data = Array.from({ length: 3 }, () => 
      Array.from({ length: 3 }, () => Math.floor(Math.random() * 100) + 20)
    )
    
    return { categories, buildings, data }
  }
}
